<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>3-css 布局</title>
    <style>
      .float {
        width: 100%;
        height: 200px;
        border: 1px solid #000;
      }
      .float div {
        float: left;
        width: 20%;
        height: 50%;
        border: 1px solid #f00;
      }
      .position {
        width: 100%;
        height: 200px;
        border: 1px solid #000;
        position: relative;
      }
      .position div {
        position: absolute;
        width: 20%;
        height: 50%;
        border: 1px solid #f00;
      }
      .flex {
        width: 100%;
        height: 200px;
        border: 1px solid #000;
        display: flex;
      }
      .flex div {
        flex: 1;
        height: 50%;
        border: 1px solid #f00;
      }
    </style>
  </head>
  <body>
    <h1>常见的布局方式</h1>
    <h2>推荐flex(弹性布局)</h2>
    <p>优点：简单，易用，兼容性好。</p>
    <p>缺点：IE10以下不支持。（算不上缺点，毕竟IE10以下用户很少）</p>
    <h2>float(浮动)</h2>
    <p>优点：简单，易用，兼容性好。</p>
    <p>缺点：容易造成布局混乱，需要清除浮动。</p>
    <h2>position(定位)</h2>
    <p>优点：简单，易用，兼容性好。</p>
    <p>缺点：需要设置宽高，容易造成布局混乱。</p>
    <div class="float">
      <div class="box">1</div>
      <div class="box">2</div>
      <div class="box">3</div>
      <div class="box">4</div>
      <div class="box">5</div>
    </div>

    <div class="position">
      <div class="box">1</div>
      <div class="box">2</div>
      <div class="box">3</div>
      <div class="box">4</div>
      <div class="box">5</div>
    </div>

    <div class="flex">
      <div class="box">1</div>
      <div class="box">2</div>
      <div class="box">3</div>
      <div class="box">4</div>
      <div class="box">5</div>
    </div>
  </body>
</html>
